#pragma once
// MESSAGE KALMAN_DATA_X PACKING

#define MAVLINK_MSG_ID_KALMAN_DATA_X 22

MAVPACKED(
typedef struct __mavlink_kalman_data_x_t {
 float xk1[13]; /*<  state prediction*/
 float xk0[13]; /*<  state fusion*/
 float delta_xk[13]; /*<  state deviation*/
 float Q[13]; /*<  state noise*/
}) mavlink_kalman_data_x_t;

#define MAVLINK_MSG_ID_KALMAN_DATA_X_LEN 208
#define MAVLINK_MSG_ID_KALMAN_DATA_X_MIN_LEN 208
#define MAVLINK_MSG_ID_22_LEN 208
#define MAVLINK_MSG_ID_22_MIN_LEN 208

#define MAVLINK_MSG_ID_KALMAN_DATA_X_CRC 107
#define MAVLINK_MSG_ID_22_CRC 107

#define MAVLINK_MSG_KALMAN_DATA_X_FIELD_XK1_LEN 13
#define MAVLINK_MSG_KALMAN_DATA_X_FIELD_XK0_LEN 13
#define MAVLINK_MSG_KALMAN_DATA_X_FIELD_DELTA_XK_LEN 13
#define MAVLINK_MSG_KALMAN_DATA_X_FIELD_Q_LEN 13

#if MAVLINK_COMMAND_24BIT
#define MAVLINK_MESSAGE_INFO_KALMAN_DATA_X { \
    22, \
    "KALMAN_DATA_X", \
    4, \
    {  { "xk1", NULL, MAVLINK_TYPE_FLOAT, 13, 0, offsetof(mavlink_kalman_data_x_t, xk1) }, \
         { "xk0", NULL, MAVLINK_TYPE_FLOAT, 13, 52, offsetof(mavlink_kalman_data_x_t, xk0) }, \
         { "delta_xk", NULL, MAVLINK_TYPE_FLOAT, 13, 104, offsetof(mavlink_kalman_data_x_t, delta_xk) }, \
         { "Q", NULL, MAVLINK_TYPE_FLOAT, 13, 156, offsetof(mavlink_kalman_data_x_t, Q) }, \
         } \
}
#else
#define MAVLINK_MESSAGE_INFO_KALMAN_DATA_X { \
    "KALMAN_DATA_X", \
    4, \
    {  { "xk1", NULL, MAVLINK_TYPE_FLOAT, 13, 0, offsetof(mavlink_kalman_data_x_t, xk1) }, \
         { "xk0", NULL, MAVLINK_TYPE_FLOAT, 13, 52, offsetof(mavlink_kalman_data_x_t, xk0) }, \
         { "delta_xk", NULL, MAVLINK_TYPE_FLOAT, 13, 104, offsetof(mavlink_kalman_data_x_t, delta_xk) }, \
         { "Q", NULL, MAVLINK_TYPE_FLOAT, 13, 156, offsetof(mavlink_kalman_data_x_t, Q) }, \
         } \
}
#endif

/**
 * @brief Pack a kalman_data_x message
 * @param system_id ID of this system
 * @param component_id ID of this component (e.g. 200 for IMU)
 * @param msg The MAVLink message to compress the data into
 *
 * @param xk1  state prediction
 * @param xk0  state fusion
 * @param delta_xk  state deviation
 * @param Q  state noise
 * @return length of the message in bytes (excluding serial stream start sign)
 */
static inline uint16_t mavlink_msg_kalman_data_x_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
                               const float *xk1, const float *xk0, const float *delta_xk, const float *Q)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
    char buf[MAVLINK_MSG_ID_KALMAN_DATA_X_LEN];

    _mav_put_float_array(buf, 0, xk1, 13);
    _mav_put_float_array(buf, 52, xk0, 13);
    _mav_put_float_array(buf, 104, delta_xk, 13);
    _mav_put_float_array(buf, 156, Q, 13);
        memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_KALMAN_DATA_X_LEN);
#else
    mavlink_kalman_data_x_t packet;

    mav_array_memcpy(packet.xk1, xk1, sizeof(float)*13);
    mav_array_memcpy(packet.xk0, xk0, sizeof(float)*13);
    mav_array_memcpy(packet.delta_xk, delta_xk, sizeof(float)*13);
    mav_array_memcpy(packet.Q, Q, sizeof(float)*13);
        memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_KALMAN_DATA_X_LEN);
#endif

    msg->msgid = MAVLINK_MSG_ID_KALMAN_DATA_X;
    return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_KALMAN_DATA_X_MIN_LEN, MAVLINK_MSG_ID_KALMAN_DATA_X_LEN, MAVLINK_MSG_ID_KALMAN_DATA_X_CRC);
}

/**
 * @brief Pack a kalman_data_x message on a channel
 * @param system_id ID of this system
 * @param component_id ID of this component (e.g. 200 for IMU)
 * @param chan The MAVLink channel this message will be sent over
 * @param msg The MAVLink message to compress the data into
 * @param xk1  state prediction
 * @param xk0  state fusion
 * @param delta_xk  state deviation
 * @param Q  state noise
 * @return length of the message in bytes (excluding serial stream start sign)
 */
static inline uint16_t mavlink_msg_kalman_data_x_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
                               mavlink_message_t* msg,
                                   const float *xk1,const float *xk0,const float *delta_xk,const float *Q)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
    char buf[MAVLINK_MSG_ID_KALMAN_DATA_X_LEN];

    _mav_put_float_array(buf, 0, xk1, 13);
    _mav_put_float_array(buf, 52, xk0, 13);
    _mav_put_float_array(buf, 104, delta_xk, 13);
    _mav_put_float_array(buf, 156, Q, 13);
        memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_KALMAN_DATA_X_LEN);
#else
    mavlink_kalman_data_x_t packet;

    mav_array_memcpy(packet.xk1, xk1, sizeof(float)*13);
    mav_array_memcpy(packet.xk0, xk0, sizeof(float)*13);
    mav_array_memcpy(packet.delta_xk, delta_xk, sizeof(float)*13);
    mav_array_memcpy(packet.Q, Q, sizeof(float)*13);
        memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_KALMAN_DATA_X_LEN);
#endif

    msg->msgid = MAVLINK_MSG_ID_KALMAN_DATA_X;
    return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_KALMAN_DATA_X_MIN_LEN, MAVLINK_MSG_ID_KALMAN_DATA_X_LEN, MAVLINK_MSG_ID_KALMAN_DATA_X_CRC);
}

/**
 * @brief Encode a kalman_data_x struct
 *
 * @param system_id ID of this system
 * @param component_id ID of this component (e.g. 200 for IMU)
 * @param msg The MAVLink message to compress the data into
 * @param kalman_data_x C-struct to read the message contents from
 */
static inline uint16_t mavlink_msg_kalman_data_x_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_kalman_data_x_t* kalman_data_x)
{
    return mavlink_msg_kalman_data_x_pack(system_id, component_id, msg, kalman_data_x->xk1, kalman_data_x->xk0, kalman_data_x->delta_xk, kalman_data_x->Q);
}

/**
 * @brief Encode a kalman_data_x struct on a channel
 *
 * @param system_id ID of this system
 * @param component_id ID of this component (e.g. 200 for IMU)
 * @param chan The MAVLink channel this message will be sent over
 * @param msg The MAVLink message to compress the data into
 * @param kalman_data_x C-struct to read the message contents from
 */
static inline uint16_t mavlink_msg_kalman_data_x_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_kalman_data_x_t* kalman_data_x)
{
    return mavlink_msg_kalman_data_x_pack_chan(system_id, component_id, chan, msg, kalman_data_x->xk1, kalman_data_x->xk0, kalman_data_x->delta_xk, kalman_data_x->Q);
}

/**
 * @brief Send a kalman_data_x message
 * @param chan MAVLink channel to send the message
 *
 * @param xk1  state prediction
 * @param xk0  state fusion
 * @param delta_xk  state deviation
 * @param Q  state noise
 */
#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS

static inline void mavlink_msg_kalman_data_x_send(mavlink_channel_t chan, const float *xk1, const float *xk0, const float *delta_xk, const float *Q)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
    char buf[MAVLINK_MSG_ID_KALMAN_DATA_X_LEN];

    _mav_put_float_array(buf, 0, xk1, 13);
    _mav_put_float_array(buf, 52, xk0, 13);
    _mav_put_float_array(buf, 104, delta_xk, 13);
    _mav_put_float_array(buf, 156, Q, 13);
    _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_KALMAN_DATA_X, buf, MAVLINK_MSG_ID_KALMAN_DATA_X_MIN_LEN, MAVLINK_MSG_ID_KALMAN_DATA_X_LEN, MAVLINK_MSG_ID_KALMAN_DATA_X_CRC);
#else
    mavlink_kalman_data_x_t packet;

    mav_array_memcpy(packet.xk1, xk1, sizeof(float)*13);
    mav_array_memcpy(packet.xk0, xk0, sizeof(float)*13);
    mav_array_memcpy(packet.delta_xk, delta_xk, sizeof(float)*13);
    mav_array_memcpy(packet.Q, Q, sizeof(float)*13);
    _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_KALMAN_DATA_X, (const char *)&packet, MAVLINK_MSG_ID_KALMAN_DATA_X_MIN_LEN, MAVLINK_MSG_ID_KALMAN_DATA_X_LEN, MAVLINK_MSG_ID_KALMAN_DATA_X_CRC);
#endif
}

/**
 * @brief Send a kalman_data_x message
 * @param chan MAVLink channel to send the message
 * @param struct The MAVLink struct to serialize
 */
static inline void mavlink_msg_kalman_data_x_send_struct(mavlink_channel_t chan, const mavlink_kalman_data_x_t* kalman_data_x)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
    mavlink_msg_kalman_data_x_send(chan, kalman_data_x->xk1, kalman_data_x->xk0, kalman_data_x->delta_xk, kalman_data_x->Q);
#else
    _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_KALMAN_DATA_X, (const char *)kalman_data_x, MAVLINK_MSG_ID_KALMAN_DATA_X_MIN_LEN, MAVLINK_MSG_ID_KALMAN_DATA_X_LEN, MAVLINK_MSG_ID_KALMAN_DATA_X_CRC);
#endif
}

#if MAVLINK_MSG_ID_KALMAN_DATA_X_LEN <= MAVLINK_MAX_PAYLOAD_LEN
/*
  This varient of _send() can be used to save stack space by re-using
  memory from the receive buffer.  The caller provides a
  mavlink_message_t which is the size of a full mavlink message. This
  is usually the receive buffer for the channel, and allows a reply to an
  incoming message with minimum stack space usage.
 */
static inline void mavlink_msg_kalman_data_x_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan,  const float *xk1, const float *xk0, const float *delta_xk, const float *Q)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
    char *buf = (char *)msgbuf;

    _mav_put_float_array(buf, 0, xk1, 13);
    _mav_put_float_array(buf, 52, xk0, 13);
    _mav_put_float_array(buf, 104, delta_xk, 13);
    _mav_put_float_array(buf, 156, Q, 13);
    _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_KALMAN_DATA_X, buf, MAVLINK_MSG_ID_KALMAN_DATA_X_MIN_LEN, MAVLINK_MSG_ID_KALMAN_DATA_X_LEN, MAVLINK_MSG_ID_KALMAN_DATA_X_CRC);
#else
    mavlink_kalman_data_x_t *packet = (mavlink_kalman_data_x_t *)msgbuf;

    mav_array_memcpy(packet->xk1, xk1, sizeof(float)*13);
    mav_array_memcpy(packet->xk0, xk0, sizeof(float)*13);
    mav_array_memcpy(packet->delta_xk, delta_xk, sizeof(float)*13);
    mav_array_memcpy(packet->Q, Q, sizeof(float)*13);
    _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_KALMAN_DATA_X, (const char *)packet, MAVLINK_MSG_ID_KALMAN_DATA_X_MIN_LEN, MAVLINK_MSG_ID_KALMAN_DATA_X_LEN, MAVLINK_MSG_ID_KALMAN_DATA_X_CRC);
#endif
}
#endif

#endif

// MESSAGE KALMAN_DATA_X UNPACKING


/**
 * @brief Get field xk1 from kalman_data_x message
 *
 * @return  state prediction
 */
static inline uint16_t mavlink_msg_kalman_data_x_get_xk1(const mavlink_message_t* msg, float *xk1)
{
    return _MAV_RETURN_float_array(msg, xk1, 13,  0);
}

/**
 * @brief Get field xk0 from kalman_data_x message
 *
 * @return  state fusion
 */
static inline uint16_t mavlink_msg_kalman_data_x_get_xk0(const mavlink_message_t* msg, float *xk0)
{
    return _MAV_RETURN_float_array(msg, xk0, 13,  52);
}

/**
 * @brief Get field delta_xk from kalman_data_x message
 *
 * @return  state deviation
 */
static inline uint16_t mavlink_msg_kalman_data_x_get_delta_xk(const mavlink_message_t* msg, float *delta_xk)
{
    return _MAV_RETURN_float_array(msg, delta_xk, 13,  104);
}

/**
 * @brief Get field Q from kalman_data_x message
 *
 * @return  state noise
 */
static inline uint16_t mavlink_msg_kalman_data_x_get_Q(const mavlink_message_t* msg, float *Q)
{
    return _MAV_RETURN_float_array(msg, Q, 13,  156);
}

/**
 * @brief Decode a kalman_data_x message into a struct
 *
 * @param msg The message to decode
 * @param kalman_data_x C-struct to decode the message contents into
 */
static inline void mavlink_msg_kalman_data_x_decode(const mavlink_message_t* msg, mavlink_kalman_data_x_t* kalman_data_x)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
    mavlink_msg_kalman_data_x_get_xk1(msg, kalman_data_x->xk1);
    mavlink_msg_kalman_data_x_get_xk0(msg, kalman_data_x->xk0);
    mavlink_msg_kalman_data_x_get_delta_xk(msg, kalman_data_x->delta_xk);
    mavlink_msg_kalman_data_x_get_Q(msg, kalman_data_x->Q);
#else
        uint8_t len = msg->len < MAVLINK_MSG_ID_KALMAN_DATA_X_LEN? msg->len : MAVLINK_MSG_ID_KALMAN_DATA_X_LEN;
        memset(kalman_data_x, 0, MAVLINK_MSG_ID_KALMAN_DATA_X_LEN);
    memcpy(kalman_data_x, _MAV_PAYLOAD(msg), len);
#endif
}
